package com.xc.ezplan.admin.controller;

import java.util.List;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xc.ezplan.admin.service.AdminEmailConfigService;
import com.xc.ezplan.admin.vo.AdminEmailConfigVo;
import com.xc.ezplan.core.base.EzResult;
import com.xc.ezplan.log.annotation.Log;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lixingchen
 * @date 2022/12/10
 * @description 邮件配置
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/email/config")
@Api(tags = "邮件配置")
public class AdminEmailConfigController {
	private final AdminEmailConfigService adminEmailConfigService;

	@Log("新增邮件配置")
	@ApiOperation("新增邮件配置")
	@PostMapping
	public EzResult<Object> createEmailConfig(@Validated @RequestBody AdminEmailConfigVo adminEmailConfigVo) {
		adminEmailConfigService.createEmailConfig(adminEmailConfigVo);
		return EzResult.ok();
	}

	@Log("更新邮件配置")
	@ApiOperation("更新邮件配置")
	@PutMapping
	public EzResult<Object> updateEmailConfig(@Validated @RequestBody AdminEmailConfigVo adminEmailConfigVo) {
		adminEmailConfigService.updateEmailConfig(adminEmailConfigVo);
		return EzResult.ok();
	}

	@Log("删除邮件配置")
	@ApiOperation("删除邮件配置")
	@DeleteMapping
	public EzResult<Object> deleteEmailConfig(@RequestBody List<Long> ids) {
		adminEmailConfigService.deleteEmailConfig(ids);
		return EzResult.ok();
	}

	@ApiOperation("查看邮件配置")
	@GetMapping
	public EzResult<Object> queryEmailConfig(@RequestParam Long id) {
		return EzResult.ok(adminEmailConfigService.queryEmailConfig(id));
	}

	@ApiOperation("按条件查询配置")
	@PostMapping("/all")
	public EzResult<Object> queryAllEmailConfig(@RequestBody(required = false) String keyWord){
		return EzResult.ok(adminEmailConfigService.queryAllEmailConfig(keyWord));
	}
}
